package tests;

import static org.junit.Assert.*;

/**
 * Tests for calTurnTime in GameLogic.java
 * 
 * @author Aditya Sehgal
 * @version 1.6
 */

import java.awt.*;

import org.junit.Test;

import MULE.Model.Game;
import MULE.Model.Player;
import MULE.Model.Race;
import MULE.Model.Resource;
import MULE.Model.Logic.GameLogic;

public class CalcTurnTimeTest {

	private final int MIN_TURN_TIME_S = 5;
	private final int SHORT_TURN_TIME_S = 30;
	private final int FULL_TURN_TIME_S = 60;

	/**
	 * Creates a new game
	 * 
	 * @return A new game object
	 */
	private Game createGame() {
		int n = Game.MIN_NUM_PLAYERS;

		return new Game(--n, Game.Difficulty.BEGINNER, null);
	}

	/**
	 * 
	 * @return GameLogic object with a new game
	 */
	private GameLogic createGameLogic() {
		return new GameLogic(null, createGame());
	}

	/**
	 * 
	 * @return New human player
	 */
	private Player createPlayer() {
		return new Player(0, "player", Race.HUMAN, Color.BLACK);
	}

	/**
	 * Tests the MIN_TURN_TIME_S condition
	 */
	@Test
	public void testInitial() {
		try {
			Player p = createPlayer();
			GameLogic g = createGameLogic();
			assertEquals(MIN_TURN_TIME_S, g.calcTurnTime(p));
		} catch (Exception x) {
			fail(x.getMessage());
		}

	}

	/**
	 * Tests the SHORT_TURN_TIME_S condition
	 */
	@Test
	public void testSHORT() {
		try {
			Player p = createPlayer();
			GameLogic g = createGameLogic();
			p.getInventory().add(Resource.FOOD, 1);
			assertEquals(SHORT_TURN_TIME_S, g.calcTurnTime(p));
		} catch (Exception x) {

		}
	}

	/**
	 * Tests the FULL_TURN_TIME_S condition
	 */
	@Test
	public void testFULL() {
		try {
			Player p = createPlayer();
			GameLogic g = createGameLogic();
			p.getInventory().add(Resource.FOOD, 10);
			assertEquals(FULL_TURN_TIME_S, g.calcTurnTime(p));

		} catch (Exception x) {
			fail(x.getMessage());
		}

	}

}
